/**
 * 用户忘记密码
 * @type {{regAction: string}}
 */
var urlParams   = {getPassAction:webRoot+"/login/getUserPass",  sendAction: webRoot + "/login/sendCode"};


$(function(){
    $(".pc-very").show();

	initEvent();
});

/**
 * 添加监听
 */
var isCheck = false;
function initEvent(){
    $(".lang-btn").click(function () {
        if(!isCheck){
            var inp = $.trim($('#pc_tel').val());
            var pass = $.md5($.trim($('#pass').val()));
            var checkPhone = MatchesClass.checkPhone(inp);
            if(checkPhone!="success"){
                alert(checkPhone);
            }else{
                isCheck = true;
                $(".pc-tel").hide();
                $(".pc-very").hide();
                $(".pc-pass").show();
                $(".lang-btn").text("确定");
            }
        }else{
            var inp = $.trim($('#pc_tel').val());
            var passport1 = $("#passport1").val();
            var passport2 = $("#passport2").val();
            var checkNewPass = MatchesClass.checkPass(passport1);
            if(passport1.length != passport2.length){
                return alert("两次新密码输入不一致!");
            }else if(checkNewPass!="success"){
                return alert(checkNewPass);
            }
            var pass = $.md5(passport1);
            $.ajax({
                type: 'post',
                url: urlParams.getPassAction,
                cache: false,
                data: {phoneNumber:inp,password:pass,verCode:$("#veri-code").val()},
                dataType: 'json',
                success: function (data) {
                    if(data){
                        alert(data.msg);
                        if(data.success){
                            window.location.href = webRoot+"login/user";
                        }
                    }
                },
                error:function(){
                }
            });
        }
    });
    $(".form-data").delegate(".send", "click", function () {
        var phone = $.trim($('#pc_tel').val());
        if (MatchesClass.checkPhone(phone)) {
            $.ajax({
                url: urlParams.sendAction,
                type: 'post',
                dataType: 'json',
                async: true,
                data: {phoneNumber: phone, type: "login"},
                success: function (data) {
                    if (data.code == '0') {

                    } else {

                    }
                },
                error: function () {

                }
            });
            var oTime = $(".form-data .time"),
                oSend = $(".form-data .send"),
                num = parseInt(oTime.text()),
                oEm = $(".form-data .time em");
            $(this).hide();
            oTime.removeClass("hide");
            var timer = setInterval(function () {
                var num2 = num -= 1;
                oEm.text(num2);
                if (num2 == 0) {
                    clearInterval(timer);
                    oSend.text("重新发送验证码");
                    oSend.show();
                    oEm.text("60");
                    oTime.addClass("hide");
                }
            }, 1000);
        }
    });
}